package com.atwork.wuhua.adapter;

import android.content.Context;
import android.support.annotation.Nullable;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.atwork.wuhua.R;
import com.atwork.wuhua.bean.FieldDetailListBean;
import com.atwork.wuhua.bean.FieldDetialBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.BaseViewHolder;

import java.util.List;

public class FieldDetialParentAdapter extends BaseQuickAdapter<FieldDetailListBean.DataBeanX.TimeSlotBean, BaseViewHolder> {
    public interface OnChildItemClick {
        void OnChildClickItem(int personPosition, int childPosition);
    }

    private FieldDetialchildAdapter fieldDetialchildAdapter;
    private Context context;


    private OnChildItemClick onChildItemClick;

    public FieldDetialParentAdapter(Context context, int layoutResId, @Nullable List<FieldDetailListBean.DataBeanX.TimeSlotBean> data) {
        super(layoutResId, data);
        this.context = context;
    }

    public void setOnChildClickItem(OnChildItemClick onChildClickItem) {
        this.onChildItemClick = onChildClickItem;
    }

    @Override
    protected void convert(final BaseViewHolder helper, final FieldDetailListBean.DataBeanX.TimeSlotBean item) {
        helper.setText(R.id.tv_time, item.getTime());
        LinearLayoutManager manager = new LinearLayoutManager(mContext);
        manager.setOrientation(LinearLayoutManager.VERTICAL);
        ((RecyclerView) helper.getView(R.id.rv_child)).setLayoutManager(manager);
        fieldDetialchildAdapter = new FieldDetialchildAdapter(context, R.layout.item_field_detial_child, item.getData());
        ((RecyclerView) helper.getView(R.id.rv_child)).setAdapter(fieldDetialchildAdapter);

        ((RecyclerView) helper.getView(R.id.rv_child)).setHasFixedSize(true);
        ((RecyclerView) helper.getView(R.id.rv_child)).setNestedScrollingEnabled(false);

        fieldDetialchildAdapter.setOnItemChildClickListener(new OnItemChildClickListener() {
            @Override
            public void onItemChildClick(BaseQuickAdapter adapter, View view, int position) {
                switch (view.getId()) {
                    case R.id.tv_name:
                        onChildItemClick.OnChildClickItem(helper.getLayoutPosition(), position);

//                        if (item.getData().get(position).isCheck()) {
//                            item.getData().get(position).setCheck(false);
//                        } else {
//                            item.getData().get(position).setCheck(true);
//                        }
//                        ((BaseQuickAdapter) ((RecyclerView) helper.getView(R.id.rv_child)).getAdapter()).setNewData(item.getData());

                        break;
                }
            }
        });
    }
}
